package com.yiwei.zxp.constant;

import android.text.TextUtils;

import com.google.gson.Gson;
import com.yiwei.zxp.Application;
import com.yiwei.zxp.api.model.InitAppModel;
import com.yiwei.zxp.api.model.LoginModel;
import com.yiwei.zxp.api.model.PayWayListModel;
import com.yiwei.zxp.api.model.UserInfoModel;
import com.yiwei.zxp.event.LoginSuccessEvent;
import com.yiwei.zxp.event.LogoutEvent;
import com.yiwei.zxp.util.DateTime;
import com.yiwei.zxp.util.PreferenceUtils;

import org.greenrobot.eventbus.EventBus;

import retrofit2.http.PUT;


/**
 * Created by xsooy-pc on 18-3-7.
 */

public class UserInfoGlobal {
    public static void saveInitData(InitAppModel.DatasBean item) {
        PreferenceUtils.putString(Application.getInstance(), "is_login", item.is_logined);
        PreferenceUtils.putString(Application.getInstance(), "lastest_version", item.version.lastest_version);
        PreferenceUtils.putString(Application.getInstance(), "download_url", item.version.download_url);
        PreferenceUtils.putString(Application.getInstance(), "upgrade_msg", item.version.upgrade_msg);
        PreferenceUtils.putString(Application.getInstance(), "service_phone", item.contact_info.service_phone);
        PreferenceUtils.putInt(Application.getInstance(), "forced_upgrade", item.version.forced_upgrade);


        PreferenceUtils.putString(Application.getInstance(), "bankcard_no", item.gathering.bankcard_no);
        PreferenceUtils.putString(Application.getInstance(), "name", item.gathering.name);
        PreferenceUtils.putString(Application.getInstance(), "bankzone", item.gathering.bankzone);

        PreferenceUtils.putString(Application.getInstance(), "day_limit", item.bank_limit.day_limit);
        PreferenceUtils.putString(Application.getInstance(), "month_limit", item.bank_limit.month_limit);
        if(item.shangjia==null){
            return;
        }
        PreferenceUtils.putString(Application.getInstance(), "shangjia_link", TextUtils.isEmpty(item.shangjia.link)?"":item.shangjia.link);
    }

    //
//
    public static void saveLoginInfo(LoginModel.DatasBean item) {
        PreferenceUtils.putString(Application.getInstance(), "email", item.email);
        PreferenceUtils.putString(Application.getInstance(), "realname", item.realname);
        PreferenceUtils.putString(Application.getInstance(), "phone", item.mobile);
        PreferenceUtils.putString(Application.getInstance(), "idno", item.idno);
        PreferenceUtils.putBoolean(Application.getInstance(), "is_dialog_open", true);
        login();
    }

    //
    public static void saveUserInfo(UserInfoModel.DatasBean item) {
        PreferenceUtils.putString(Application.getInstance(), "username", item.username);
        PreferenceUtils.putString(Application.getInstance(), "phone", item.phone);
        PreferenceUtils.putString(Application.getInstance(), "realname", item.realname);
        PreferenceUtils.putString(Application.getInstance(), "idno", item.idno);
        PreferenceUtils.putString(Application.getInstance(), "email", item.email);
        PreferenceUtils.putString(Application.getInstance(), "commission", item.commission);
        PreferenceUtils.putString(Application.getInstance(), "total", item.total);
        PreferenceUtils.putString(Application.getInstance(), "freeze", item.freeze);
        PreferenceUtils.putString(Application.getInstance(), "balance", item.balance);
        PreferenceUtils.putString(Application.getInstance(), "invite_id", item.invite_id);
        PreferenceUtils.putString(Application.getInstance(), "isset_pay_password", item.isset_pay_password);
        PreferenceUtils.putString(Application.getInstance(), "shop_name", item.shop_name);
        PreferenceUtils.putString(Application.getInstance(), "icon", item.icon);
        PreferenceUtils.putString(Application.getInstance(), "invite_code", item.invite_code);

    }


    public static String getUserName() {
        return PreferenceUtils.getString(Application.getInstance(), "username", "");
    }

    public static String getIcon() {
        return PreferenceUtils.getString(Application.getInstance(), "icon", "");
    }

    public static void getSetPayPass() {
        PreferenceUtils.putString(Application.getInstance(), "isset_pay_password", "1");
    }

    public static boolean getIssetPayPass() {
        if (PreferenceUtils.getString(Application.getInstance(), "isset_pay_password", "").equals("1")) {
            return true;
        } else {
            return false;
        }

    }

    public static void setDialogOnce(boolean isOpen) {
        PreferenceUtils.putBoolean(Application.getInstance(), "is_dialog_open", isOpen);
    }

    public static boolean isDialogOnce() {
        return PreferenceUtils.getBoolean(Application.getInstance(), "is_dialog_open", true);
    }

    public static String getBankDayLimit() {
        return PreferenceUtils.getString(Application.getInstance(), "day_limit", "");
    }

    public static String getBankMonthLimit() {
        return PreferenceUtils.getString(Application.getInstance(), "month_limit", "");
    }

    //    是否店铺审核成功
    public static boolean isHasShopName() {
        if (PreferenceUtils.getString(Application.getInstance(), "shop_success", "").equals("1")) {
            return true;
        } else {
            return false;
        }
    }

    //    店铺审核状态
    public static String getShopNameStatus() {
        return PreferenceUtils.getString(Application.getInstance(), "shop_success", "");

    }

    //    店铺审核状态
    public static void setIsHasShopName(String shop_success) {
        PreferenceUtils.putString(Application.getInstance(), "shop_success", shop_success);
    }

    public static String hasInviteCode() {
        return PreferenceUtils.getString(Application.getInstance(), "invite_code", "");
    }

    public static void setInviteCode(String invite_code) {
        PreferenceUtils.putString(Application.getInstance(), "invite_code", invite_code);
    }

    public static void setShopName(String shopName) {
        PreferenceUtils.putString(Application.getInstance(), "shop_name", shopName);
    }

    public static String getShopName() {
        return PreferenceUtils.getString(Application.getInstance(), "shop_name", "");
    }

    public static String getTTB() {
        return PreferenceUtils.getString(Application.getInstance(), "balance", "0");
    }

    public static String getPhone() {
        return PreferenceUtils.getString(Application.getInstance(), "phone", "");
    }

    public static String getBalance() {
        return PreferenceUtils.getString(Application.getInstance(), "balance", "0");
    }

    public static String getCommission() {
        return PreferenceUtils.getString(Application.getInstance(), "commission", "0");
    }

    public static boolean isLogin() {
        if (PreferenceUtils.getString(Application.getInstance(), "is_login", "0").equals("1")) {
            return true;
        } else {
            return false;
        }
    }

    public static void login() {
        PreferenceUtils.putString(Application.getInstance(), "is_login", "1");
        EventBus.getDefault().post(new LoginSuccessEvent());
    }

    public static void logout() {
        PreferenceUtils.putString(Application.getInstance(), "token", "");
        PreferenceUtils.putString(Application.getInstance(), "is_login", "");
        EventBus.getDefault().post(new LogoutEvent());
    }

    public static String getShangjiaWebUrl(){
        return PreferenceUtils.getString(Application.getInstance(), "shangjia_link", "");
    }

}
